#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "lrj";
# 第一章小说url地址
url = 'http://www.biquges.com/52_52642/25585323.html'
url = 'http://www.biquges.com/52_52642/25585323.html'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
print(response.text)
response.encoding = response.apparent_encoding


def get_one_novel(html_url):
    # 调用请求网页数据函数
    response = get_response(html_url)
    # 转行成selector解析对象
    selector = parsel.Selector(response.text)
    # 获取小说标题
    title = selector.css('.bookname h1::text').get()
    # 获取小说内容 返回的是list
    content_list = selector.css('#content::text').getall()
    # ''.join(列表) 把列表转换成字符串
    content_str = ''.join(content_list)
    print(title, content_str)


if __name__ == '__main__':
    url = 'http://www.biquges.com/52_52642/25585323.html'
    get_one_novel(url)
def save(title, content):
    """
    保存小说
    :param title: 小说章节标题
    :param content: 小说内容
    :return:
    """
    # 路径
    filename = f'{title}\\'
    # os 内置模块，自动创建文件夹
    if os.makedirs(filename):
        os.mkdir()
    # 一定要记得加后缀 .txt  mode 保存方式 a 是追加保存  encoding 保存编码
    with open(filename + title + '.txt', mode='a', encoding='utf-8') as f:
        # 写入标题
        f.write(title)
        # 换行
        f.write('\n')
        # 写入小说内容
        f.write(content)
